﻿using System.Diagnostics;
using System.Xml.Linq;

namespace Bing
{
    /// <summary>
    /// You can include more than one <see cref="ApiHelper.SourceType"/> in a request. In fact, you can include all SourceTypes listed in Working with SourceTypes (Bing, Version 2.x)
    /// </summary>
    [DebuggerDisplay("Error Count: {Error.Count}")]
    public class MultipleSourceResponse: SearchResponseBase
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="MultipleSourceResponse"/> class.
        /// </summary>
        /// <param name="element"></param>
        public MultipleSourceResponse(XContainer element) : base(element)
        {

        }

        /// <summary>
        /// Gets or sets the ad response.
        /// </summary>
        /// <value>An <see cref="AdResponse" /> object.</value>
        public AdResponse AdResponse { get; set; }
        /// <summary>
        /// Gets or sets the image response.
        /// </summary>
        /// <value>A <see cref="ImageResponse" /> object.</value>
        public ImageResponse ImageResponse { get; set; }
        /// <summary>
        /// Gets or sets the instant answer response.
        /// </summary>
        /// <value>An <see cref="InstantAnswerResponse" /> object.</value>
        public InstantAnswerResponse InstantAnswerResponse { get; set; }
        /// <summary>
        /// Gets or sets the mobile web response.
        /// </summary>
        /// <value>A <see cref="MobileWebResponse" /> object.</value>
        public MobileWebResponse MobileWebResponse { get; set; }
        /// <summary>
        /// Gets or sets the news response.
        /// </summary>
        /// <value>A <see cref="NewsResponse" /> object.</value>
        public NewsResponse NewsResponse { get; set;  }
        /// <summary>
        /// Gets or sets the phonebook response.
        /// </summary>
        /// <value>A <see cref="PhonebookResponse" />.</value>
        public PhonebookResponse PhonebookResponse { get; set; }
        /// <summary>
        /// Gets or sets the related search response.
        /// </summary>
        /// <value>A <see cref="RelatedSearchResponse" /> object.</value>
        public RelatedSearchResponse RelatedSearchResponse { get; set; }
        /// <summary>
        /// Gets or sets the spell response.
        /// </summary>
        /// <value>A <see cref="SpellResponse" /> object.</value>
        public SpellResponse SpellResponse { get; set; }
        /// <summary>
        /// Gets or sets the translation response.
        /// </summary>
        /// <value>A <see cref="TranslationResponse" /> object.</value>
        public TranslationResponse TranslationResponse { get; set; }
        /// <summary>
        /// Gets or sets the video response.
        /// </summary>
        /// <value>A <see cref="VideoResponse" /> object.</value>
        public VideoResponse VideoResponse { get; set; }
        /// <summary>
        /// Gets or sets the web response.
        /// </summary>
        /// <value>A <see cref="WebResponse" /> object.</value>
        public WebResponse WebResponse { get; set; }

        /// <summary>
        /// Parses the response from the Bing API.
        /// </summary>
        /// <param name="element">The XML from the Bing API</param>
        /// <returns>An <see cref="MultipleSourceResponse" /></returns>
        public static MultipleSourceResponse ParseElement(XContainer element)
        {
            MultipleSourceResponse multipleSourceResponse = new MultipleSourceResponse(element);

            multipleSourceResponse.AdResponse = AdResponse.ParseElement(element);
            multipleSourceResponse.ImageResponse = ImageResponse.ParseElement(element);
            multipleSourceResponse.InstantAnswerResponse = InstantAnswerResponse.ParseElement(element);
            multipleSourceResponse.MobileWebResponse = MobileWebResponse.ParseElement(element);
            multipleSourceResponse.NewsResponse = NewsResponse.ParseElement(element);
            multipleSourceResponse.PhonebookResponse = PhonebookResponse.ParseElement(element);
            multipleSourceResponse.RelatedSearchResponse = RelatedSearchResponse.ParseElement(element);
            multipleSourceResponse.SpellResponse = SpellResponse.ParseElement(element);
            multipleSourceResponse.TranslationResponse = TranslationResponse.ParseElement(element);
            multipleSourceResponse.VideoResponse = VideoResponse.ParseElement(element);
            multipleSourceResponse.WebResponse = WebResponse.ParseElement(element);
            return multipleSourceResponse;
        }
    }
}
